package config

import (
	"flag"
	"os"
)

var helpMessage = `Usage: 
    -a, --arch <arch>       Architecture, used for package naming, default is amd64
    -d, --data <data_dir>   Read repo config from <data_dir>
    -o, --output <dir>      Save files to <dir>, default to current dir
    -h, --help              Show this help message
    -p, --proxy <url>       Download files from github proxy <url>
    --dry-run               Dry run with HTTP head method (do not download)

用法: 
    -a, --arch <arch>       架构，用于包的命名，默认是 amd64
    -d, --data <data_dir>   从 <data_dir> 读取仓库配置
    -o, --output <dir>      将文件保存到 <dir>，默认为当前文件夹
    -h, --help              显示该帮助信息
    -p, --proxy <url>       从 Github 代理 <url> 下载文件
    --dry-run               用 http 的 head 方法试运行（不下载文件）
`

// 读取命令行参数
func ReadArgs() {
	// architecture
	flag.StringVar(&Architecture, "a", "amd64", "")
	flag.StringVar(&Architecture, "arch", "amd64", "")
	// data_dir
	flag.StringVar(&DataDir, "d", "data", "")
	flag.StringVar(&DataDir, "data", "data", "")
	// output_dir
	flag.StringVar(&OutputDir, "o", ".", "")
	flag.StringVar(&OutputDir, "output", ".", "")
	// proxy
	flag.StringVar(&Proxy, "p", "", "")
	flag.StringVar(&Proxy, "proxy", "", "")
	// dry_run
	dry_run := flag.Bool("dry-run", false, "")
	// help
	var help bool
	flag.BoolVar(&help, "h", false, "")
	flag.BoolVar(&help, "help", false, "")

	flag.Parse()

	if help {
		print(helpMessage)
		os.Exit(0)
	}
	Config["dry-run"] = *dry_run
}
